const app = getApp();
Component({
  options: {
    styleIsolation: 'shared' 
  },
  /**
   * 组件的属性列表
   */
  properties: {
    evaluation_show: {
      type: Boolean,
      value: false
    },
    order_id: {
      type: null,
      value: ""
    },
    urlStr: {
      type: String,
      value: "plugin.be-within-call.frontend.need-order-operate.push-remark"
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    starList:[{
      id: 1,
      isShow: false
    },{
      id: 2,
      isShow: false
    },{
      id: 3,
      isShow: false
    },{
      id: 4,
      isShow: false
    },{
      id: 5,
      isShow: false
    }],
  },
  lifetimes: {
    attached() {
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    evaluation() {
      this.setData({
        evaluation_show: false
      })
    },
    clickStar(ev) {
      let index = ev.currentTarget.dataset.index;
      for(let [cindex,citem] of this.data.starList.entries()) {
        if(index == 0 && this.data.starList.filter(item => item.isShow).length == 1) {
          this.setData({
            ["starList[" +cindex + "].isShow"] : false
          })
          return
        }

        if(cindex <= index ){
          this.setData({
            ["starList[" +cindex + "].isShow"] : true
          })
        }else {
          this.setData({
            ["starList[" +cindex + "].isShow"] : false
          })
        }
      }
    },
    sure() {
      let newArr = this.data.starList.filter(item => item.isShow);
      let baseUrl = app.getNetAddresss(this.data.urlStr);
      app._postNetWork({
        url: baseUrl,
        data: { oid : this.data.order_id , star: newArr.length },
        success: ({data : { data,result,msg }}) => {
          if (result !== 1) {
            app.tips(msg)
            return false;
          }
          this.setData({
            evaluation_show: false
          })
          this.triggerEvent('commentEvent');
        }
      });
    }
  }
})
